package com.centaline.androidsalesblog.rx.database;

import com.centaline.androidsalesblog.constants.CommonConstant;
import com.centaline.androidsalesblog.model.businissobject.DropBo;
import com.centaline.androidsalesblog.model.databaseobject.SearchDataDo;

import java.util.ArrayList;

import rx.functions.Func1;

/**
 * SearchData<p>
 * 满足需求,接口使用Value字段请求
 * Created by guilin on 16/1/25.
 */
public class NewEstSearchDataFunc1 implements Func1<ArrayList<SearchDataDo>, ArrayList<DropBo>> {

    private final int type;
    private final boolean addLimit;

    public NewEstSearchDataFunc1(int type) {
        this(type, false);
    }

    public NewEstSearchDataFunc1(int type, boolean addLimit) {
        this.type = type;
        this.addLimit = addLimit;
    }

    @Override
    public ArrayList<DropBo> call(ArrayList<SearchDataDo> searchDataDos) {
        final ArrayList<DropBo> list = new ArrayList<>();
        DropBo dropBo;
        if (addLimit) {
            dropBo = new DropBo(type);
            dropBo.setText(CommonConstant.DROP_TEXT_NO_LIMITED);
            dropBo.setValue(CommonConstant.DROP_VALUE_NULL);
            list.add(dropBo);
        }
        for (SearchDataDo searchDataDo : searchDataDos) {
            if (80 == type && ("不限".endsWith(searchDataDo.getText()) ||
                    "全部".endsWith(searchDataDo.getText()))) {
                continue;
            }
            dropBo = new DropBo(type);
            dropBo.setText(searchDataDo.getText().trim());
            dropBo.setValue(String.valueOf(searchDataDo.getValue()));
            list.add(dropBo);
        }
        return list;
    }

}
